package ntu.metaweb.result;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class ContactListConverter implements Converter {

  public void marshal(Object source, HierarchicalStreamWriter writer,
          MarshallingContext context) {
      ContactList contactlist = (ContactList) source;
      writer.startNode("returncode");
      writer.setValue(Integer.toString(contactlist.returncode));
      writer.endNode();
      writer.startNode("followed");
      for (String s : contactlist.followed) {
      	writer.startNode("user");
      	writer.setValue(s);
      	writer.endNode();
      }
      writer.endNode();
      writer.startNode("follower");
      for (String s : contactlist.followed) {
      	writer.startNode("user");
      	writer.setValue(s);
      	writer.endNode();
      }
      writer.endNode();
  }

  public Object unmarshal(HierarchicalStreamReader reader,
          UnmarshallingContext context) {
  	return null;
  }

  public boolean canConvert(Class type) {
      return type.equals(ContactList.class);
  }
}

